<template>
	<view class="container">
		<!-- 商品列表 -->
		<view class="product-list">
			<view class="product-item" v-for="(item, index) in productList" :key="index">
				<image :src="item.image" mode="aspectFill" class="product-img"></image>
				<view class="product-info">
					<text class="product-name">{{item.name}}</text>
					<text class="product-specs">{{item.specs}}</text>
				</view>
			</view>
		</view>
		
		<!-- 评分 -->
		<view class="rating-section">
			<text class="section-title">商品评分</text>
			<view class="rating-stars">
				<text 
					class="star" 
					v-for="i in 5" 
					:key="i"
					:class="{ active: rating >= i }"
					@click="setRating(i)"
				>★</text>
			</view>
		</view>
		
		<!-- 评价内容 -->
		<view class="content-section">
			<text class="section-title">评价内容</text>
			<textarea 
				v-model="content" 
				class="content-input" 
				placeholder="请输入您的评价内容（最少10个字）"
				maxlength="500"
			></textarea>
			<text class="word-count">{{content.length}}/500</text>
		</view>
		
		<!-- 图片上传 -->
		<view class="upload-section">
			<text class="section-title">上传图片</text>
			<view class="upload-list">
				<view 
					class="upload-item" 
					v-for="(item, index) in imageList" 
					:key="index"
				>
					<image :src="item" mode="aspectFill" class="preview-img"></image>
					<text class="delete-btn" @click="deleteImage(index)">×</text>
				</view>
				<view class="upload-btn" @click="chooseImage" v-if="imageList.length < 9">
					<text class="upload-icon">+</text>
					<text class="upload-text">上传图片</text>
				</view>
			</view>
			<text class="upload-tip">最多上传9张图片</text>
		</view>
		
		<!-- 匿名评价 -->
		<view class="anonymous-section">
			<text class="section-title">匿名评价</text>
			<switch :checked="isAnonymous" @change="toggleAnonymous" color="#D02B29" />
		</view>
		
		<!-- 提交按钮 -->
		<view class="footer">
			<button class="submit-btn" @click="submitReview">提交评价</button>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue'

// 商品列表
const productList = ref([
	{
		id: 101,
		name: '重庆老火锅底料',
		specs: '500g',
		image: 'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg'
	},
	{
		id: 102,
		name: '特色花椒油',
		specs: '200ml',
		image: 'https://img.alicdn.com/imgextra/i2/O1CN01F0MA5j1zXb0XcYV1F_!!6000000006733-0-tps-1316-736.jpg'
	}
])

// 评分
const rating = ref(5)

// 评价内容
const content = ref('')

// 图片列表
const imageList = ref([])

// 是否匿名
const isAnonymous = ref(false)

// 设置评分
const setRating = (value) => {
	rating.value = value
}

// 选择图片
const chooseImage = () => {
	uni.chooseImage({
		count: 9 - imageList.value.length,
		success: (res) => {
			imageList.value = [...imageList.value, ...res.tempFilePaths]
		}
	})
}

// 删除图片
const deleteImage = (index) => {
	imageList.value.splice(index, 1)
}

// 切换匿名状态
const toggleAnonymous = (e) => {
	isAnonymous.value = e.detail.value
}

// 提交评价
const submitReview = () => {
	if (content.value.length < 10) {
		uni.showToast({
			title: '评价内容不能少于10个字',
			icon: 'none'
		})
		return
	}
	
	uni.showLoading({
		title: '提交中...'
	})
	
	// 这里可以添加提交评价的接口调用
	setTimeout(() => {
		uni.hideLoading()
		uni.showToast({
			title: '评价成功',
			icon: 'success'
		})
		
		// 返回订单列表
		setTimeout(() => {
			uni.redirectTo({
				url: '/pages/order/list'
			})
		}, 1500)
	}, 2000)
}
</script>

<style>
.container {
	min-height: 100vh;
	background-color: #F5F5F5;
	padding-bottom: 120rpx;
}

/* 商品列表样式 */
.product-list {
	background-color: #FFFFFF;
	padding: 20rpx;
	margin-bottom: 20rpx;
}

.product-item {
	display: flex;
	margin-bottom: 20rpx;
}

.product-item:last-child {
	margin-bottom: 0;
}

.product-img {
	width: 160rpx;
	height: 160rpx;
	border-radius: 10rpx;
	margin-right: 20rpx;
}

.product-info {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.product-name {
	font-size: 28rpx;
	color: #333;
	margin-bottom: 10rpx;
}

.product-specs {
	font-size: 24rpx;
	color: #999;
}

/* 评分样式 */
.rating-section {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 20rpx;
	display: block;
}

.rating-stars {
	display: flex;
}

.star {
	font-size: 50rpx;
	color: #DDDDDD;
	margin-right: 20rpx;
}

.star.active {
	color: #FFD700;
}

/* 评价内容样式 */
.content-section {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
	position: relative;
}

.content-input {
	width: 100%;
	height: 200rpx;
	font-size: 28rpx;
	color: #333;
	line-height: 1.5;
}

.word-count {
	position: absolute;
	right: 30rpx;
	bottom: 30rpx;
	font-size: 24rpx;
	color: #999;
}

/* 图片上传样式 */
.upload-section {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.upload-list {
	display: flex;
	flex-wrap: wrap;
	margin: 0 -10rpx;
}

.upload-item {
	width: 200rpx;
	height: 200rpx;
	margin: 10rpx;
	position: relative;
}

.preview-img {
	width: 100%;
	height: 100%;
	border-radius: 10rpx;
}

.delete-btn {
	position: absolute;
	top: -20rpx;
	right: -20rpx;
	width: 40rpx;
	height: 40rpx;
	line-height: 40rpx;
	text-align: center;
	background-color: rgba(0, 0, 0, 0.5);
	color: #FFFFFF;
	border-radius: 50%;
	font-size: 32rpx;
}

.upload-btn {
	width: 200rpx;
	height: 200rpx;
	margin: 10rpx;
	background-color: #F5F5F5;
	border-radius: 10rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.upload-icon {
	font-size: 60rpx;
	color: #999;
	margin-bottom: 10rpx;
}

.upload-text {
	font-size: 24rpx;
	color: #999;
}

.upload-tip {
	font-size: 24rpx;
	color: #999;
	margin-top: 20rpx;
	display: block;
}

/* 匿名评价样式 */
.anonymous-section {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
}

/* 底部提交按钮样式 */
.footer {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	height: 100rpx;
	background-color: #FFFFFF;
	display: flex;
	align-items: center;
	padding: 0 30rpx;
}

.submit-btn {
	width: 100%;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	background-color: #D02B29;
	color: #FFFFFF;
	border-radius: 40rpx;
	font-size: 32rpx;
}
</style> 